package sb.de.advanceShopper.dataBase;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class ShopsSQLiteHelper extends SQLiteOpenHelper {
	
	private static final int DB_VER = 1;
	private static final String DB_NAME = "adv_shopper.db";
	public static final String SHOPS_TABLE = "shops";

	//columns
	public static final String SHOPS_TCID = "_id";
	public static final String SHOPS_TCNAME = "name";
	public static final String SHOPS_TCCITY = "city";
	public static final String SHOPS_TCLONGITUDE = "longitude";
	public static final String SHOPS_TCLATITUDE = "latitude";
	public static final String SHOPS_TCDESCRIPTION = "description";

	public static final String SHOPS_TCREATE = "CREATE TABLE "
			+ SHOPS_TABLE + " (" + SHOPS_TCID
			+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + SHOPS_TCNAME
			+ " TEXT NOT NULL, " + SHOPS_TCCITY + " INTEGER NOT NULL, " + SHOPS_TCLONGITUDE + " REAL, "
			+ SHOPS_TCLATITUDE + " REAL, " + SHOPS_TCDESCRIPTION + " TEXT);";

	public static final String SHOPS_SELECT_ALL = "SELECT * FROM " + DB_NAME
			+ "." + SHOPS_TABLE + ";";

	public ShopsSQLiteHelper(Context context) {
		super(context, DB_NAME, null, DB_VER);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(SHOPS_TCREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(ShopsSQLiteHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + SHOPS_TABLE);
		onCreate(db);
	}

}